package com.jsmtr.rms.utils.ExcelImportHelper.service.impl;

import com.jsmtr.rms.entity.BaseUser;
import com.jsmtr.rms.entity.HRUsers;
import com.jsmtr.rms.utils.DateTools;
import com.jsmtr.rms.utils.ExcelImportHelper.dao.JDBCHelper;
import com.jsmtr.rms.utils.ExcelImportHelper.service.IImportResultService;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
 * @author: cyx
 * @description:
 * @date: Created in 2018/11/21 9:46
 * @modified by:
 */

public class ImportResultService implements IImportResultService {

    private static SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

    //region 保存简历筛选
    @Override
    public Integer saveResumeResult(BaseUser baseUser, String pid, String fid, String cardNo, String sorce, String result, String remark) throws Exception {
        List parms=new ArrayList();
        String sql="update duserresume d set ";
        if (sorce!=null&&!sorce.equalsIgnoreCase("")){
            sql+=" ";
        }

        if (result!=null&&!result.equalsIgnoreCase("")){
            sql+=" d.state=?, ";
            parms.add(result);
        }

        if (remark!=null&&!remark.equalsIgnoreCase("")){
            sql+=" d.sxbz=?, ";
            parms.add(remark);
        }

        if (baseUser!=null){
            sql+=" d.edituserid=?, ";
            sql+=" d.editusername=?, ";
            sql+=" d.editdate=?, ";
            parms.add(baseUser.getId());
            parms.add(baseUser.getUname());
            parms.add(new java.sql.Date(System.currentTimeMillis()));
        }else{
            throw new Exception("登录账户过期，请重新登录！");
        }

         if(cardNo!=null&&!cardNo.equalsIgnoreCase("")){
             sql+=" d.id=? where d.id=? ";
             parms.add(cardNo);
             parms.add(cardNo);
         }else{
             throw new Exception("导入人员不能为空！");
         }
        if (fid!=null&&!fid.equalsIgnoreCase("")){
            sql+=" and d.path like '%"+fid+"%' " ;
            //parms.add(fid);
        }else{
            throw new Exception("导入流程节点不能为空！");
        }

        if (pid!=null&&!pid.equalsIgnoreCase("")){
            sql+=" and d.proid=? ";
            parms.add(pid);
        }
        int dbresult=-1;

        JDBCHelper jdbcHelper=new JDBCHelper();
        jdbcHelper.setSql(sql);
        jdbcHelper.setSqlValues(parms);
        dbresult=jdbcHelper.executeUpdate();
        return dbresult;
    }
    //endregion

    //region 保存初审结果
    @Override
    public Integer saveRecommendResult(BaseUser baseUser,String pid, String fid, String cardNo, String sorce, String result, String remark) throws Exception {
        List parms=new ArrayList();
        String sql="update duserresume d set ";
        if (sorce!=null&&!sorce.equalsIgnoreCase("")){
            sql+=" ";
        }

        if (result!=null&&!result.equalsIgnoreCase("")){
            sql+=" d.state=?, ";
            parms.add(result);
        }

        if (remark!=null&&!remark.equalsIgnoreCase("")){
            sql+=" d.sxbz=?, ";
            parms.add(remark);
        }

        if (baseUser!=null){
            sql+=" d.edituserid=?, ";
            sql+=" d.editusername=?, ";
            sql+=" d.editdate=?, ";
            parms.add(baseUser.getId());
            parms.add(baseUser.getUname());
            parms.add(new java.sql.Date(System.currentTimeMillis()));
        }else{
            throw new Exception("登录账户过期，请重新登录！");
        }

        if(cardNo!=null&&!cardNo.equalsIgnoreCase("")){
            sql+=" d.id=? where d.id=? ";
            parms.add(cardNo);
            parms.add(cardNo);
        }else{
            throw new Exception("导入人员不能为空！");
        }
        if (fid!=null&&!fid.equalsIgnoreCase("")){
            sql+=" and d.path like '%"+fid+"%' " ;
            //parms.add(fid);
        }else{
            throw new Exception("导入流程节点不能为空！");
        }

        if (pid!=null&&!pid.equalsIgnoreCase("")){
            sql+=" and d.proid=? ";
            parms.add(pid);
        }
        int dbresult=-1;

        JDBCHelper jdbcHelper=new JDBCHelper();
        jdbcHelper.setSql(sql);
        jdbcHelper.setSqlValues(parms);
        dbresult=jdbcHelper.executeUpdate();
        return dbresult;
    }
    //endregion

    //region 导入资料审核
    @Override
    public Integer saveCheckResult(BaseUser baseUser, String pid, String fid, String cardNo, String sorce, String result, String remark) throws Exception {
        List parms=new ArrayList();
        String sql="update duserresume d set ";
        if (sorce!=null&&!sorce.equalsIgnoreCase("")){
            sql+=" ";
        }

        if (result!=null&&!result.equalsIgnoreCase("")){
            sql+=" d.zlstate=?, ";
            parms.add(result);
        }

        if (remark!=null&&!remark.equalsIgnoreCase("")){
            sql+=" d.zlremark=?, ";
            parms.add(remark);
        }

        if (baseUser!=null){
            sql+=" d.zluid=?, ";
            sql+=" d.zluname=?, ";
            sql+=" d.zldate=?, ";
            parms.add(baseUser.getId());
            parms.add(baseUser.getUname());
            parms.add(new java.sql.Date(System.currentTimeMillis()));
        }else{
            throw new Exception("登录账户过期，请重新登录！");
        }

        if(cardNo!=null&&!cardNo.equalsIgnoreCase("")){
            sql+=" d.id=? where d.id=? ";
            parms.add(cardNo);
            parms.add(cardNo);
        }else{
            throw new Exception("导入人员不能为空！");
        }
        if (fid!=null&&!fid.equalsIgnoreCase("")){
            sql+=" and d.path like '%"+fid+"%' " ;
            //parms.add(fid);
        }else{
            throw new Exception("导入流程节点不能为空！");
        }

        if (pid!=null&&!pid.equalsIgnoreCase("")){
            sql+=" and d.proid=? ";
            parms.add(pid);
        }
        int dbresult=-1;

        JDBCHelper jdbcHelper=new JDBCHelper();
        jdbcHelper.setSql(sql);
        jdbcHelper.setSqlValues(parms);
        dbresult=jdbcHelper.executeUpdate();
        return dbresult;
    }
    //endregion


    //region 保存背景调查结果
    @Override
    public Integer saveReviewResult(BaseUser baseUser,String pid, String fid, String cardNo, String sorce, String result, String remark) throws Exception {
        List parms=new ArrayList();
        String sql="update duserresume d set ";
        if (sorce!=null&&!sorce.equalsIgnoreCase("")){
            sql+=" ";
        }

        if (result!=null&&!result.equalsIgnoreCase("")){
            sql+=" d.zsstate=?, ";
            parms.add(result);
        }

        if (remark!=null&&!remark.equalsIgnoreCase("")){
            sql+=" d.zsremark=?, ";
            parms.add(remark);
        }

        if (baseUser!=null){
            sql+=" d.zsuid=?, ";
            sql+=" d.zsuname=?, ";
            sql+=" d.zsdate=?, ";
            parms.add(baseUser.getId());
            parms.add(baseUser.getUname());
            parms.add(new java.sql.Date(System.currentTimeMillis()));
        }else{
            throw new Exception("登录账户过期，请重新登录！");
        }

        if(cardNo!=null&&!cardNo.equalsIgnoreCase("")){
            sql+=" d.id=? where d.id=? ";
            parms.add(cardNo);
            parms.add(cardNo);
        }else{
            throw new Exception("导入人员不能为空！");
        }
        if (fid!=null&&!fid.equalsIgnoreCase("")){
            sql+=" and d.path like '%"+fid+"%' " ;
            //parms.add(fid);
        }else{
            throw new Exception("导入流程节点不能为空！");
        }

        if (pid!=null&&!pid.equalsIgnoreCase("")){
            sql+=" and d.proid=? ";
            parms.add(pid);
        }
        int dbresult=-1;

        JDBCHelper jdbcHelper=new JDBCHelper();
        jdbcHelper.setSql(sql);
        jdbcHelper.setSqlValues(parms);
        dbresult=jdbcHelper.executeUpdate();
        return dbresult;
    }
    //endregion

    //region 保存面试结果
    @Override
    public Integer saveInterviewResult(BaseUser baseUser,String pid, String fid, String cardNo, String sorce, String result, String remark) throws Exception {
        List parms=new LinkedList();
        String sql="update doms_user d set ";
        if (sorce!=null&&!sorce.equalsIgnoreCase("")){
            sql+=" d.point=?, ";
            parms.add(sorce);
        }

        if (result!=null&&!result.equalsIgnoreCase("")){
            sql+=" d.result=?, ";
            parms.add(result);
        }

        if (remark!=null&&!remark.equalsIgnoreCase("")){
            sql+=" d.scoringrules=?, ";
            parms.add(remark);
        }

        if (baseUser!=null){
            // sql+=" d.bduid=?, ";
            sql+=" d.pointuser=?, ";
            sql+=" d.pointdate=?, ";
            //parms.add(baseUser.getId());
            parms.add(baseUser.getUname());
            parms.add(new java.sql.Date(System.currentTimeMillis()));
        }else{
            throw new Exception("登录账户过期，请重新登录！");
        }

        if(cardNo!=null&&!cardNo.equalsIgnoreCase("")){
            sql+=" d.userid=?  where d.userid=? ";
            parms.add(cardNo);
            parms.add(cardNo);
        }else{
            throw new Exception("导入人员不能为空！");
        }
        if (fid!=null&&!fid.equalsIgnoreCase("")){
            sql+=" and d.fid like '%"+fid+"%' " ;
            //parms.add(fid);
        }else{
            throw new Exception("导入流程节点不能为空！");
        }

        /*if (pid!=null&&!pid.equalsIgnoreCase("")){
            sql+=" and d.pid=? ";
            parms.add(pid);
        }*/
        int dbresult=-1;

        JDBCHelper jdbcHelper=new JDBCHelper();
        jdbcHelper.setSql(sql);
        jdbcHelper.setSqlValues(parms);
        dbresult=jdbcHelper.executeUpdate();
        return dbresult;
    }
    //endregion

    //region 保存笔试结果
    @Override
    public Integer saveExamResult(BaseUser baseUser,String pid, String fid, String cardNo, String sorce, String result, String remark) throws Exception {
        List parms=new LinkedList();
        String sql="update dobs_user d set ";
        if (sorce!=null&&!sorce.equalsIgnoreCase("")){
            sql+=" d.point=?, ";
            parms.add(sorce);
        }

        if (result!=null&&!result.equalsIgnoreCase("")){
            sql+=" d.result=?, ";
            parms.add(result);
        }

        if (remark!=null&&!remark.equalsIgnoreCase("")){
            sql+=" d.remark=?, ";
            parms.add(remark);
        }

        if (baseUser!=null){
            // sql+=" d.bduid=?, ";
            sql+=" d.pointuser=?, ";
            sql+=" d.pointdate=sysdate, ";
            //parms.add(baseUser.getId());
            parms.add(baseUser.getUname());
           // parms.add(new java.sql.Date(System.currentTimeMillis()));
        }else{
            throw new Exception("登录账户过期，请重新登录！");
        }

        if(cardNo!=null&&!cardNo.equalsIgnoreCase("")){
            sql+=" d.userid=? where d.userid=? ";
            parms.add(cardNo);
            parms.add(cardNo);
        }else{
            throw new Exception("导入人员不能为空！");
        }
        if (fid!=null&&!fid.equalsIgnoreCase("")){
            sql+=" and d.fid like '%"+fid+"%' " ;
            //parms.add(fid);
        }else{
            throw new Exception("导入流程节点不能为空！");
        }

        /*if (pid!=null&&!pid.equalsIgnoreCase("")){
            sql+=" and d.pid=? ";
            parms.add(pid);
        }*/
        int dbresult=-1;

        JDBCHelper jdbcHelper=new JDBCHelper();
        jdbcHelper.setSql(sql);
        jdbcHelper.setSqlValues(parms);
        dbresult=jdbcHelper.executeUpdate();
        return dbresult;
    }
    //endregion

    //region 保存体检结果
    @Override
    public Integer savePhysicalResult(BaseUser baseUser,String pid, String fid, String cardNo, String sorce, String result, String remark) throws Exception {
        List parms=new ArrayList();
        String sql="update duserresume d set ";
        if (sorce!=null&&!sorce.equalsIgnoreCase("")){
            sql+=" ";
        }

        if (result!=null&&!result.equalsIgnoreCase("")){
            sql+=" d.tjstate=?, ";
            parms.add(result);
        }

        if (remark!=null&&!remark.equalsIgnoreCase("")){
            sql+=" d.tjremark=?, ";
            parms.add(remark);
        }

        if (baseUser!=null){
            sql+=" d.tjuid=?, ";
            sql+=" d.tjuname=?, ";
            sql+=" d.tjdate=?, ";
            parms.add(baseUser.getId());
            parms.add(baseUser.getUname());
            parms.add(new java.sql.Date(System.currentTimeMillis()));
        }else{
            throw new Exception("登录账户过期，请重新登录！");
        }

        if(cardNo!=null&&!cardNo.equalsIgnoreCase("")){
            sql+=" d.id=? where d.id='"+cardNo+"' ";
            parms.add(cardNo);
            //parms.add(cardNo);
        }else{
            throw new Exception("导入人员不能为空！");
        }
        if (fid!=null&&!fid.equalsIgnoreCase("")){
            sql+=" and d.path like '%"+fid+"%' " ;
            //parms.add(fid);
        }else{
            throw new Exception("导入流程节点不能为空！");
        }

        if (pid!=null&&!pid.equalsIgnoreCase("")){
            sql+=" and d.proid='"+pid+"' ";
            //parms.add(pid);
        }
        int dbresult=-1;

        JDBCHelper jdbcHelper=new JDBCHelper();
        jdbcHelper.setSql(sql);
        jdbcHelper.setSqlValues(parms);
        dbresult=jdbcHelper.executeUpdate();
        return dbresult;
    }
    //endregion

    //region 保存实习结果(高中职招聘用)
    @Override
    public Integer savePracticeResult(BaseUser baseUser,String pid, String fid, String cardNo, String sorce, String result, String remark) throws Exception {
        List parms=new ArrayList();
        String sql="update hr_zzuser d set ";
        if (sorce!=null&&!sorce.equalsIgnoreCase("")){
            sql+=" ";
        }

        if (result!=null&&!result.equalsIgnoreCase("")){
            sql+=" d.sxstate=?, ";
            parms.add(result);
        }

        if (remark!=null&&!remark.equalsIgnoreCase("")){
            sql+=" d.sxremark=?, ";
            parms.add(remark);
        }

        if (baseUser!=null){
            sql+=" d.sxuid=?, ";
            sql+=" d.sxuname=?, ";
            sql+=" d.sxdate=?, ";
            parms.add(baseUser.getId());
            parms.add(baseUser.getUname());
            parms.add(new java.sql.Date(System.currentTimeMillis()));
        }else{
            throw new Exception("登录账户过期，请重新登录！");
        }

        if(cardNo!=null&&!cardNo.equalsIgnoreCase("")){
            sql+=" d.id=? where d.id=? ";
            parms.add(cardNo);
            parms.add(cardNo);
        }else{
            throw new Exception("导入人员不能为空！");
        }
        if (fid!=null&&!fid.equalsIgnoreCase("")){
            sql+=" and d.path like '%"+fid+"%' " ;
            //parms.add(fid);
        }else{
            throw new Exception("导入流程节点不能为空！");
        }

        if (pid!=null&&!pid.equalsIgnoreCase("")){
            sql+=" and d.pid=? ";
            parms.add(pid);
        }
        int dbresult=-1;

        JDBCHelper jdbcHelper=new JDBCHelper();
        jdbcHelper.setSql(sql);
        jdbcHelper.setSqlValues(parms);
        dbresult=jdbcHelper.executeUpdate();
        return dbresult;
    }
    //endregion


    //region 保存实作结果（社会招聘）
    @Override
    public Integer saveOperationResult(BaseUser baseUser,String pid, String fid, String cardNo, String sorce, String result, String remark) throws Exception {
        List parms=new ArrayList();
        String sql="update DOOPERATION_USER d set ";
        if (sorce!=null&&!sorce.equalsIgnoreCase("")){
            sql+=" d.point=?, ";
            parms.add(sorce);
        }

        if (result!=null&&!result.equalsIgnoreCase("")){
            sql+=" d.result=?, ";
            parms.add(result);
        }

        if (remark!=null&&!remark.equalsIgnoreCase("")){
            sql+=" d.bz=?, ";
            parms.add(remark);
        }

        if (baseUser!=null){
           // sql+=" d.bduid=?, ";
            sql+=" d.pointuser=?, ";
            sql+=" d.pointdate=?, ";
            //parms.add(baseUser.getId());
            parms.add(baseUser.getUname());
            parms.add(new java.sql.Date(System.currentTimeMillis()));
        }else{
            throw new Exception("登录账户过期，请重新登录！");
        }

        if(cardNo!=null&&!cardNo.equalsIgnoreCase("")){
            sql+=" d.userid=? where d.userid=? ";
            parms.add(cardNo);
            parms.add(cardNo);
        }else{
            throw new Exception("导入人员不能为空！");
        }
        if (fid!=null&&!fid.equalsIgnoreCase("")){
            sql+=" and d.path like '%"+fid+"%' " ;
            //parms.add(fid);
        }else{
            throw new Exception("导入流程节点不能为空！");
        }

       /* if (pid!=null&&!pid.equalsIgnoreCase("")){
            sql+=" and d.proid=? ";
            parms.add(pid);
        }*/


        int dbresult=-1;

        JDBCHelper jdbcHelper=new JDBCHelper();
        jdbcHelper.setSql(sql);
        jdbcHelper.setSqlValues(parms);
        dbresult=jdbcHelper.executeUpdate();
        return dbresult;
    }
    //endregion

    //region 保存录用结果
    @Override
    public Integer saveEmployResult(BaseUser baseUser,String pid, String fid, String cardNo, String sorce, String result, String remark) throws Exception {
        List parms=new ArrayList();
        String sql="update duserresume d set ";
        if (sorce!=null&&!sorce.equalsIgnoreCase("")){
            sql+=" ";
        }

        if (result!=null&&!result.equalsIgnoreCase("")){
            sql+=" d.bdstate=?, ";
            parms.add(result);
        }

        if (remark!=null&&!remark.equalsIgnoreCase("")){
            sql+=" d.bdremark=?, ";
            parms.add(remark);
        }

        if (baseUser!=null){
            sql+=" d.bduid=?, ";
            sql+=" d.bduname=?, ";
            sql+=" d.bddate=?, ";
            parms.add(baseUser.getId());
            parms.add(baseUser.getUname());
            parms.add(new java.sql.Date(System.currentTimeMillis()));
        }else{
            throw new Exception("登录账户过期，请重新登录！");
        }

        if(cardNo!=null&&!cardNo.equalsIgnoreCase("")){
            sql+=" d.id=? where d.id=? ";
            parms.add(cardNo);
            parms.add(cardNo);
        }else{
            throw new Exception("导入人员不能为空！");
        }
        if (fid!=null&&!fid.equalsIgnoreCase("")){
            sql+=" and d.path like '%"+fid+"%' " ;
            //parms.add(fid);
        }else{
            throw new Exception("导入流程节点不能为空！");
        }

        if (pid!=null&&!pid.equalsIgnoreCase("")){
            sql+=" and d.proid=? ";
            parms.add(pid);
        }
        int dbresult=-1;

        JDBCHelper jdbcHelper=new JDBCHelper();
        jdbcHelper.setSql(sql);
        jdbcHelper.setSqlValues(parms);
        dbresult=jdbcHelper.executeUpdate();
        return dbresult;
    }

    @Override
    public Integer saveSigingResult(BaseUser baseUser, String pid, String fid, String cardNo, String sorce, String result, String remark) throws Exception {
        List parms=new ArrayList();
        String sql="update duserresume d set ";
        if (sorce!=null&&!sorce.equalsIgnoreCase("")){
            sql+=" ";
        }

        if (result!=null&&!result.equalsIgnoreCase("")){
            sql+=" d.qystate=?, ";
            parms.add(result);
        }

        if (remark!=null&&!remark.equalsIgnoreCase("")){
            sql+=" d.qyremark=?, ";
            parms.add(remark);
        }

        if (baseUser!=null){
            sql+=" d.qyuid=?, ";
            sql+=" d.qyuname=?, ";
            sql+=" d.qydate=?, ";
            parms.add(baseUser.getId());
            parms.add(baseUser.getUname());
            parms.add(new java.sql.Date(System.currentTimeMillis()));
        }else{
            throw new Exception("登录账户过期，请重新登录！");
        }

        if(cardNo!=null&&!cardNo.equalsIgnoreCase("")){
            sql+=" d.id=? where d.id=? ";
            parms.add(cardNo);
            parms.add(cardNo);
        }else{
            throw new Exception("导入人员不能为空！");
        }
        if (fid!=null&&!fid.equalsIgnoreCase("")){
            sql+=" and d.path like '%"+fid+"%' " ;
            //parms.add(fid);
        }else{
            throw new Exception("导入流程节点不能为空！");
        }

        if (pid!=null&&!pid.equalsIgnoreCase("")){
            sql+=" and d.proid=? ";
            parms.add(pid);
        }
        int dbresult=-1;

        JDBCHelper jdbcHelper=new JDBCHelper();
        jdbcHelper.setSql(sql);
        jdbcHelper.setSqlValues(parms);
        dbresult=jdbcHelper.executeUpdate();
        return dbresult;
    }
    //endregion



}
